package com.fengye.school.controller;

import com.fengye.school.model.school.Grade;
import com.fengye.school.response.ResponsePageResult;
import com.fengye.school.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 专业设置控制器
 * @author sky
 * @date 2021/4/22 10:58
 */
@RestController
@RequestMapping("/grade")
public class GradeController {

    @Autowired
    private GradeService gradeService;

    @PostMapping("/save")
    public Grade save(@RequestBody Grade grade) {
        return gradeService.save(grade);
    }

    @GetMapping("/list")
    public List<Grade> list() {
        return gradeService.list();
    }

    @GetMapping("/list/page")
    public ResponsePageResult<Grade> listByPage(int page, int limit) {
        return gradeService.listByPage(Math.max((page - 1), 0), limit);
    }

    @DeleteMapping("/delete/all")
    public void deleteAll(Long[] ids){
        Arrays.stream(ids).forEach(System.out::println);
        gradeService.deleteAll(ids);
    }

    @DeleteMapping("/delete/id/{id}")
    public void deleteById(@PathVariable(name = "id", required = true)Long id){
        gradeService.deleteById(id);
    }
    

    
}
